package com.demo.house.controller;

import com.demo.house.common.Result;
import com.demo.house.entity.HouseSourse;
import com.demo.house.entity.User;
import com.demo.house.entity.UserHouse;
import com.demo.house.service.HouseSourseService;
import com.demo.house.service.UserHouseService;
import com.demo.house.vo.RequestVo.HouseSourseVo;
import com.demo.house.vo.RequestVo.HouseUrlSourseVo;
import com.demo.house.vo.RequestVo.UserHouseRentVo;
import com.demo.house.vo.RequestVo.UserHouseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping(value = "UserHouse/")
@RestController
public class UserHouseController {
    @Autowired
    private UserHouseService userHouseService;

    @Autowired
    private HouseSourseService houseSourseService;

/*    *//**
     * 修改房源的状态
     * @param vo
     * @return
     *//*
    @RequestMapping("update3")
    public Result update(@RequestBody UserHouseVo vo){
        UserHouseVo userHouseVo = new UserHouseVo();
        userHouseVo.setId(vo.getId());
        userHouseVo.setEndTime(vo.getEndTime());
        userHouseVo.setStartTime(vo.getStartTime());
        return Result.getSuccess().setData(userHouseService.updateByPrimaryKey(userHouseVo));
    }*/
    @PutMapping("update3")
    public Result update(@RequestBody UserHouseVo vo){
        System.out.println(vo);
        return Result.getSuccess().setData(userHouseService.updateByPrimaryKey(vo));
    }

    /**查询租房信息
     * */
    @GetMapping("/rent/{id}")
    public Result selectByuseId(@PathVariable Integer id){
        List<UserHouse> userHouses = userHouseService.selectHouseByuseId(id);
        System.out.println(id+" "+userHouses);
          return Result.getSuccess().setData(userHouseService.selectHouseByuseId(id));
    }

    /* 新增租房信息
    * */
    @PutMapping("/insert")
    public Result insertRent(@RequestBody UserHouseRentVo userHouseRentVo){
        System.out.println(userHouseRentVo);
        return Result.getSuccess().setData(userHouseService.insertSelective(userHouseRentVo));
    }

    /*修改state字段，上下架*/
    @PutMapping("/update1")
    public Result updateStatus(@RequestBody HouseSourse houseSourse){
/*        HouseSourse houseSourse = new HouseSourse();
        houseSourse.setId(vo.getId());
        houseSourse.setState(vo.getState());*/
        return Result.getSuccess().setData(houseSourseService.updateState(houseSourse));
    }

    /**根据house_sourse_id查询房源信息
     * @return
     */
    @GetMapping("selectName/{id}")
    public Result selectName(@PathVariable Integer id){
        List<UserHouse> userHouses=userHouseService.selectName(id);
        return Result.getSuccess().setData(userHouses);
    }

}
